// ========================= Tabbar页面：购物车 ========================= 

Page({
  data: {
    // 获取胶囊菜单距离顶部的位置
    menuTop: getApp().menuCapsulePosition.top,
    cardListHeight: 0,
    allState: true,
    product: {
      commodity_id: '1',
      commodity_sideshow: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2F06.imgmini.eastday.com%2Fmobile%2F20180515%2F20180515173401_8dd9676594c443a36983a1dfaa36f6b5_1.jpeg&refer=http%3A%2F%2F06.imgmini.eastday.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612246161&t=ffd052acb9792eca2e6e78b5c60d1c84',
      commodity_price: '23.00',
      commodity_name: '新鲜大大大菠菜熟读速度是300g',
      commodity_count: 10,
      commodity_status: true,
    },
    goods: {
      "commodity_id": 14,
      "commodity_type": "时令水果",
      "commodity_original": "4.9",
      "commodity_price": "4",
      "commodity_name": "白心火龙果",
      "commodity_units": "个",
      "commodity_synopsis": "低糖清甜 , 膳食纤维含量高",
      "commodity_brand": "无",
      "commodity_specification": "300g",
      "commodity_place": "越南",
      "commodity_images": [
        "http://192.168.2.191:8083/CommoditySideshow/1609919276095.jpg",
        "http://192.168.2.191:8083/CommoditySideshow/1609919276095.jpg",
        "http://192.168.2.191:8083/CommoditySideshow/1609919276095.jpg",
      ],
      "commodity_sideshow": ['http://192.168.2.191:8083/CommoditySideshow/1609919276095.jpg'],
      "commodity_number": 100,
      "selectAmount": 1
    }
  },

  onLoad: function () {
    this.initHeight()
  },
  /**
   * 每次进入购物车页面时初始化购物车的徽标,防止徽标初始化失败(取消订单时将订单商品放回到购物车)
   */
  onShow() {
    //将所有商品添加到购物车后初始化购物车徽标
    getApp().initialCartTabBarBadge()
  },
  // 初始化列表高度、宽度
  initHeight: function () {
    wx.getSystemInfo({
      success: (result) => {
        const windowHeight = result.windowHeight
        this.setData({
          //  屏幕可用高度减去自定义底部导航栏高度，得出屏幕中内容展示的高度
          cardListHeight: windowHeight - this.data.menuTop - 45 - 50,
        })
        console.log(this.data.cardListHeight);
      },
    })
  },
  // 提交订单
  submitOrder: function () {
    wx.navigateTo({
      url: '/pages/cart/submit-order/submit-order',
    })
    console.log("点击了跳转提交订单页面按钮");
  }
})